<?php 

    $num_a = 0;
    
?><div id="content_worktimes" name="content_worktimes" style="padding-left:0px"><br><h2>Arbeitsplanung</h2><ul>
    <li><a href="/worktime">Arbeitsplanung</a></li>&nbsp;&nbsp;<li><a href="#" id="a_delete"><?php print ($this->helperArray['modus']=="wt") ? ("Arbeitszeit"):("Verfügbarkeit"); ?> entfernen</a></li>&nbsp;&nbsp;<?php
    if($this->helperArray['modus']=="av") {
        print '<li><a href="/worktime/availabilitytoworktime/id/'.$this->id.'">Arbeitseinträge für diese Verfügbarkeit generieren</a></li>';
    }
    if($this->helperArray['modus']=="wt") {
        $num_a = count($this->alternatives);
        if(count($num_a)>0)
            print '<li><a href="#" id="a_alternatives">('.$num_a.') Alternativperson'.(($num_a==1) ? "":"en").' vorhanden</a></li>';
        else
            print '<li>(0) Alternativpersonen vorhanden</li>';
    }    
?></ul><div id="div_delete" name="div_delete" style="display:none;width:100%" align="left"><br>
<form>
    <input id="b_del_row" type="button" onClick="parent.location='/worktime/delete/id/<?php print $this->id;?>'" value="Datensatz entfernen" style="padding:5px;border:1px solid #900000;background-color:#900000;color:#FFFFFF">&nbsp;<?php 
    if($this->serieId>0) 
        print'<input id="b_del_serie" type="button" onClick="parent.location=\'/worktime/delete/ids/'.$this->serieId.'\'" value="Ganze Serie entfernen" style="padding:5px;border:1px solid #900000;background-color:#900000;color:#FFFFFF">&nbsp;'; 
    ?><input id="b_break" type="button" value="Abbrechen" style="padding:5px;border:1px solid #888888">
</form></div>
<div id="div_alternatives" name="div_alternatives" style="display:none;width:100%" align="left"><br>
<form method="post" action="/worktime/bookalternative/id/<?php print $this->id; ?>" enctype="application/x-www-form-urlencoded" id="form_alternatives" name="form_alternatives"><?php 

    if($num_a && $this->helperArray['modus']=="wt") {
        print '<select name="alternative_worker" id="alternative_worker" style="padding:3px">';
        foreach($this->alternatives as $aa) {
            print'<option value="'.$aa['id'].'" label="'.$aa['name'].'">'.$aa['name'].'</option>';
        }
        print '</select><br>';

        print'<input id="b_book_alternative" type="submit" value="Die Arbeitszeit auf die Alternativperson umbuchen" style="padding:5px;border:1px solid #009000;background-color:#009000;color:#FFFFFF">&nbsp;
        <input id="b_break_1" type="button" value="Abbrechen" style="padding:5px;border:1px solid #888888">';
    }

?>
</form></div><hr><br><b><?php print $this->modus;?> - Editieren</b>
<br>Bitte benutzen Sie das untere Formular um den Eintrag zu editieren.
<?php
$this->headScript()->appendFile('/libs/jquery-ui-timepicker-addon.js');
$this->headScript()->appendFile('/libs/js/event/event-form.js');
$this->headLink()->appendStylesheet('/libs/css/jquery.timepicker.css');
$this->headScript()->appendFile('/libs/time.js');
$this->headScript()->appendFile('/libs/date.js');
?>
<script>

    $('#a_delete').click(function() {
      $('#div_delete').fadeIn('slow', function() {
      });
      $('#div_alternatives').fadeOut('slow', function() {
      });      
    });
    $('#b_break').click(function() {
      $('#div_delete').fadeOut('slow', function() {
      });
    });<?php if($num_a && $this->helperArray['modus']=="wt") 
    print"\$('#a_alternatives').click(function() {
      \$('#div_alternatives').fadeIn('slow', function() {
      });
      \$('#div_delete').fadeOut('slow', function() {
      });      
    });    
    \$('#b_break_1').click(function() {
      \$('#div_alternatives').fadeOut('slow', function() {
      });
    });";?>    
    $(function() {
        dateFrom=Date.parseExact($('#date_from').val(),'dd.MM.yyyy HH:mm');
        dateTo=Date.parseExact($('#date_to').val(),'dd.MM.yyyy HH:mm');
        dateDifference=new TimeSpan(dateTo-dateFrom);
        $('#date_from').change(function(){
            $('#date_to').val(Date.parseExact($('#date_from').val(),'dd.MM.yyyy HH:mm').add({ days: dateDifference.days, hours: dateDifference.hours, minutes: dateDifference.minutes}).toString('dd.MM.yyyy HH:mm'));
        });
        $('#date_to').change(function(){
            dateFrom=Date.parseExact($('#date_from').val(),'dd.MM.yyyy HH:mm');
            dateTo=Date.parseExact($('#date_to').val(),'dd.MM.yyyy HH:mm');
            dateDifference=new TimeSpan(dateTo-dateFrom);
        });     
	    $('#date_from').datetimepicker({
	        showSecond: false,
	        dateFormat: 'dd.mm.yy',
	        timeFormat: 'HH:mm:ss',
	    });
	    $('#date_to').datetimepicker({
	        showSecond: false,
	        dateFormat: 'dd.mm.yy',
	        timeFormat: 'HH:mm:ss',
	    });
	    $('#serie_from').datetimepicker({
	        showSecond: false,
	        dateFormat: 'dd.mm.yy'
	    });
	    $('#serie_to').datetimepicker({
	        showSecond: false,
	        dateFormat: 'dd.mm.yy'
	    });

        // elements below are not needed for the update layout
        $('#expire_date-label').hide();
        $('#expire_date-element').hide();
        // statisfy the date validator 
        $('#expire_date').val('<?php print '11.11.'.date('Y').' 11:11';?>');
        $('#once_serie-label').hide();
        $('#once_serie-element').hide();
        $('#x_days-label').hide();
        $('#x_days-element').hide();       
    });
</script>
<div id="div_errors" name="div_errors"><?php 
    if(0<strlen($this->errors)) 
    print $this->errors; 
?></div>
<?php 
    print $this->form;
?>
</div>
